<?php
	
class Table_Photos extends Zend_Db_Table_Abstract
{
    protected $_name    = 'photo';
    protected $_primary = array('PHOTO_NUMERO','VIP_NUMERO');
    protected $_sequence = false;
 	
	public function afficherPhotoOfficielle($idVip){
		return $this->fetchRow($this
			->select()
			->where('photo_numero = 1 and vip_numero = ?', $idVip)
			
			);
	}
	
	public function afficherAlbumPhoto(){
		return $this->fetchAll($this
			->select()
			->where('photo_numero = 1')
			->order('photo_adresse')
			
			);
	}
	
	public function rechercheMaxphoto($numVip){
		return $this->fetchRow($this
			->select()
			->from($this, array('numPhoto' => 'MAX(PHOTO_NUMERO)'))
			->where('VIP_NUMERO = ?', $numVip)
			
			);
	}
	
	public function insertPhotoOfficielle($idPhoto, $numVip, $sujetPhoto, $comPhoto, $adrPhoto){
		$data = array('PHOTO_NUMERO'=> $idPhoto, 
		'VIP_NUMERO'=> $numVip, 'PHOTO_SUJET' => $sujetPhoto,
		'PHOTO_COMMENTAIRE' => $comPhoto, 'PHOTO_ADRESSE' => $adrPhoto);		
		$this->insert($data);
	}
	
	public function insertPhotos($idPhoto, $numVip, $sujetPhoto, $comPhoto, $adrPhoto){
		$data = array('PHOTO_NUMERO'=> $idPhoto+1, 
		'VIP_NUMERO'=> $numVip, 'PHOTO_SUJET' => $sujetPhoto,
		'PHOTO_COMMENTAIRE' => $comPhoto, 'PHOTO_ADRESSE' => $adrPhoto);		
		$this->insert($data);
	}
	public function supprPhotos($id){
		
		$this->delete('VIP_NUMERO ='.(int)$id);
	}
	
	public function getPhoto($idPhoto, $idVip)
	{
		return $this -> fetchRow($this
			->select()
			->where('photo_numero = ?', $idPhoto)
			->where('vip_numero = ?', $idVip)
		);
	}

	public function getAdressePhoto($idPhoto, $idVip)
	{
		return $this -> fetchRow($this
			->select()
			->from($this, array('photo_adresse'))
			->where('photo_numero = ?', $idPhoto)
			->where('vip_numero = ?', $idVip)
		);
	}
	
	public function getCommentairePhoto($idPhoto, $idVip)
	{
		return $this -> fetchRow($this
			->select()
			->from($this, array('photo_commentaire'))
			->where('photo_numero = ?', $idPhoto)
			->where('vip_numero = ?', $idVip)
		);
	}
	public function getPhotoPrincipale($idVip)
	{
		return $this->fetchRow($this->select()
                                    ->where('VIP_NUMERO = ?', $idVip)
                                    ->where('PHOTO_NUMERO = ?', 1)
                                );
	}
	
	public function getAllphotos($id)
	{
		return $this->fetchAll($this->select()
									->from($this, array('*'))
                                    ->where('VIP_NUMERO = ?', $id)
                                );
	}
	
	public function getVipAyantPhoto(){
		return $this->fetchAll($this->select()
									->from($this, array('*'))
		);
	}
	
}